home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / VU External Tool libs / FileToolHost.vuLib < prev    next >
Encoding:
Text File  |  1998-03-19  |  16.7 KB  |  510 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        FileToolHost.vulib
  5. #
  6. #    Contains:    The tool definition along with the high level tasks to access
  7. #                the tool's services
  8. #
  9. #    Written by:    P. Nagarajan
  10. #
  11. #    Copyright:    © 1993-1997 by Apple Computer, Inc., all rights reserved.
  12. #
  13. # ****************************************************************************
  14. #            C h a n g e        H i s t o r y (most recent first):
  15. # ****************************************************************************
  16. #
  17. #        Vers      Date        Author        Description
  18. #        ----    --------    ------    ---------------------------------------------
  19. #        2.2.2    02/04/97    JAS        Added 'vers' resources to library.
  20. #                                    These should always match tool version when tool is revved.
  21. #                02/04/97    JAS        Added task InitFindFolderGlobalsHost()
  22. #         <1>     2/23/96    JC        first checked in (Created to support TRACS output data).
  23. #         <2>      2/1/95    RV        change FileExists return value from integer to boolean symbol
  24. #                 3/26/93    NAGA    xxx put comment here xxx
  25. #
  26. #    To Do:
  27. #################################################################################
  28. tool FileToolHost s:'FILE'
  29. begin    
  30.     # Services specific to FileToolHost:
  31.     
  32.         # To create a file
  33.     Service    "Create"( 'string', 'string', 'string' ) return 'integer';
  34.     # First parameter is the full pathname for the file 
  35.     # Second parameter is the 4 character creator type ( eg., 'MPS ') 
  36.     # Third parameter is the 4 character file type (eg., 'TEXT') 
  37.     # Return value is the file reference number for future calls
  38.     
  39.     # To create a folder
  40.     Service    "CreateFolder"( 'string' ) return 'integer';
  41.     # First parameter is the full pathname for the file 
  42.     # Return value is the file reference number for future calls
  43.     
  44.     # To delete a file/folder
  45.     Service    "Delete"( 'string', 'integer' );
  46.     # First parameter is the full pathname for the file (can be '', if second
  47.     # parameter is given non zero value)
  48.     # Second parameter if non-zero is the file reference previously 
  49.     # returned by the tool
  50.     # Once a file/folder is deleted its reference number is no longer valid
  51.  
  52.     # To erase the contents of the data fork of a file
  53.     Service    "Erase"( 'string', 'integer' ) return 'integer';
  54.     # First parameter is the full pathname for the file (can be '', if second
  55.     # parameter is given non zero value)
  56.     # Second parameter if non-zero is the file reference previously 
  57.     # returned by the tool
  58.  
  59.     # To check if a file exists
  60.     Service    "FileExists"( 'string' ) return 'symbol';
  61.     # First parameter is the full pathname for the file (can be '', if second
  62.     # parameter is given non zero value)
  63.     # Return value is 1 if file exists else 0
  64.  
  65.     # To copy a file
  66.     Service    "CopyFile"( 'string', 'integer', 'string' ) return 'integer';
  67.     # First parameter is the full pathname for the file (can be '', if second
  68.     # parameter is given non zero value)
  69.     # Second parameter if non-zero is the file reference previously 
  70.     # returned by the tool. This can be zero if the first parameter
  71.     # is fully specified.
  72.     # Third parameter is the full pathname for the new file
  73.     # Return value is 1 if file copied else 0
  74.  
  75.     # To get back memory in the FileTool heap
  76.     Service    "ForgetFile"( 'string', 'integer' ) return 'integer';
  77.     # First parameter is the full pathname for the file (can be '', if second
  78.     # parameter is given non zero value)
  79.     # Second parameter if non-zero is the file reference previously 
  80.     # returned by the tool
  81.     # Return value is insignificant
  82.  
  83.     # To move a file/folder
  84.     Service    "Move"( 'string', 'integer', 'string' ) return 'integer';
  85.     # First parameter is the full pathname for the file (can be '', if second
  86.     # parameter is given non zero value)
  87.     # Second parameter if non-zero is the file reference previously 
  88.     # returned by the tool
  89.     # Third parameter is the new file path name
  90.     # Return value is the file reference number for future calls
  91.  
  92.     # To read from a file a specified number of characters
  93.     Service    "Read"( 'string', 'integer', 'integer', 'integer' ) return 'string';
  94.     # First parameter is the full pathname for the file (can be '', if second
  95.     # parameter is given non zero value)
  96.     # Second parameter if non-zero is the file reference previously 
  97.     # returned by the tool
  98.     # Third parameter is the number of characters to be read
  99.     # Fourth parameter is the number of characters from start of file after
  100.     # which to start reading
  101.     # Return value is the string read from the file
  102.  
  103.     # To read from a file until a specified character is seen
  104.     Service    "ReadUntil"( 'string', 'integer', 'string', 'integer' ) return 'string';
  105.     # First parameter is the full pathname for the file (can be '', if second
  106.     # parameter is given non zero value)
  107.     # Second parameter if non-zero is the file reference previously 
  108.     # returned by the tool
  109.     # Third parameter is the single character string that indicates the
  110.     # character until which the contents of a file has to be read
  111.     # Fourth parameter is the number of characters from start of file after
  112.     # which to start reading
  113.     # Return value is the string read from the file
  114.  
  115.     # To rename a file/folder
  116.     Service    "Rename"( 'string', 'integer', 'string' ) return 'integer';
  117.     # First parameter is the full pathname for the file (can be '', if second
  118.     # parameter is given non zero value)
  119.     # Second parameter if non-zero is the file reference previously 
  120.     # returned by the tool
  121.     # Third parameter is the new file name (not a path name)
  122.     # Return value is the file reference number for future calls
  123.  
  124.     # To get back the list of mounted volume names
  125.     Service    "VolumeList"() return 'list';
  126.     
  127.     # To write to the data fork of a file
  128.     Service    "Write"( 'string', 'integer', 'string' ) return 'integer';
  129.     # First parameter is the full pathname for the file (can be '', if second
  130.     # parameter is given non zero value)
  131.     # Second parameter if non-zero is the file reference previously 
  132.     # returned by the tool
  133.     # Third parameter is the text to be appended to (written at the end
  134.     # of) the file specified by the first two parameters
  135.     # Return value is the file reference number for future calls
  136.  
  137.     # To append the second file to the first, both must be text files
  138.     Service    "AppendFile"( 'string', 'string' ) return 'symbol';
  139.  
  140.     # To locate the special folders defined by the system
  141.     Service    "FindFolder"( 'string' ) return 'string';
  142.     # First parameter is the four character code for the folder, the FolderType
  143.     # The full path name to the folder is returned 
  144.  
  145.     # Read the short & long version string from the specified file
  146.     Service    "ReadVersion"( 'string', 'integer' ) return 'list';
  147.  
  148.     # Test if a resource exists within a specified file
  149.     Service    "ResourceExists"( 'string', 'string', 'integer' ) return 'symbol';
  150.     # Return value is true if the resource exists.
  151.  
  152.     # Read the 'SIZE' resource from an application file
  153.     Service    "ReadSizeResource"( 'string', 'integer' ) return 'list';
  154.     # First parameter is the full pathname of the application
  155.     # Second parameter is the ID of the 'SIZE' resource to be read
  156.     # Returns the preferred and minimum memory partitions (in bytes)
  157.  
  158.     # Services common to all Virtual User external tools:
  159.     Service "Initialize"( 'undefined' ); # pass TRUE for target, FALSE for host
  160.      Service "Cancel"( 'string' );
  161.     Service "GetToolServices"() return 'list';
  162.     Service "GetToolVersion"() return 'list';
  163.     Service "ServiceSupported"( 'string' ) return 'undefined';
  164.     Service "Quit"();
  165.     
  166. end;
  167.  
  168. task CreateFileHost( pFilePathName, pSignature := 'MPS ', pType := 'TEXT' )
  169. begin
  170.     return FileToolHost( "Create", pFilePathName, pSignature, pType ); 
  171. end;
  172.  
  173. task CreateFolderHost( pFolderPathName )
  174. begin
  175.     return FileToolHost( "CreateFolder", pFolderPathName ); 
  176. end;
  177.  
  178. task DeleteFileHost( pFileReference )
  179. begin
  180.     if( typeOf( pFileReference ) = 'integer' )
  181.     begin
  182.         tFilePathStr := '';
  183.         tFileReferenceNumber := pFileReference;
  184.     end;
  185.     else if( typeOf( pFileReference ) = 'string' )
  186.     begin
  187.         tFilePathStr := pFileReference;
  188.         tFileReferenceNumber := 0;
  189.     end;
  190.     else
  191.         return -50;#gParamError = -50, same as what the tool returns
  192.     
  193.     # Now call the tool with tFilePathStr, tFileReferenceNumber as parameters
  194.     return FileToolHost( "Delete", tFilePathStr, tFileReferenceNumber ); 
  195.     
  196. end;
  197.  
  198. # This task will empty the contents of the specified file (dataFork only)
  199. # the file will not be deleted
  200. task EraseFileHost( pFileReference )
  201. begin
  202.     if( typeOf( pFileReference ) = 'integer' )
  203.     begin
  204.         tFilePathStr := '';
  205.         tFileReferenceNumber := pFileReference;
  206.     end;
  207.     else if( typeOf( pFileReference ) = 'string' )
  208.     begin
  209.         tFilePathStr := pFileReference;
  210.         tFileReferenceNumber := 0;
  211.     end;
  212.     else
  213.         return -50;#gParamError = -50, same as what the tool returns
  214.     
  215.     # Now call the tool with tFilePathStr, tFileReferenceNumber as parameters
  216.     return FileToolHost( "Erase", tFilePathStr, tFileReferenceNumber ); 
  217.     
  218. end;
  219.  
  220. task FileExistsHost( pFilePathName )
  221. begin
  222.     if( typeOf( pFilePathName ) <> 'string' )
  223.     begin
  224.         return -50;#gParamError = -50, same as what the tool returns
  225.     end;
  226.     
  227.     # Now call the tool with pFilePathName as parameter
  228.     return FileToolHost( "FileExists", pFilePathName ); 
  229.     
  230. end;
  231.  
  232. task FileCopyHost( pFileReference, pDestPathName )
  233. begin
  234.     if( typeOf( pFileReference ) = 'integer' )
  235.     begin
  236.         tFilePathStr := '';
  237.         tFileReferenceNumber := pFileReference;
  238.     end;
  239.     else if( typeOf( pFileReference ) = 'string' )
  240.     begin
  241.         tFilePathStr := pFileReference;
  242.         tFileReferenceNumber := 0;
  243.     end;
  244.     else
  245.         return -50;#gParamError = -50, same as what the tool returns
  246.     
  247.     # Now call the tool with tFilePathStr, tFileReferenceNumber and pDestPathName as parameters
  248.     return FileToolHost( "CopyFile", tFilePathStr, tFileReferenceNumber, pDestPathName ); 
  249.     
  250. end;
  251.  
  252. # This task will free up memory in the FileTool
  253. # the file will not be touched or affected in any way
  254. task ForgetFileHost( pFileReference )
  255. begin
  256.     if( typeOf( pFileReference ) = 'integer' )
  257.     begin
  258.         tFilePathStr := '';
  259.         tFileReferenceNumber := pFileReference;
  260.     end;
  261.     else if( typeOf( pFileReference ) = 'string' )
  262.     begin
  263.         tFilePathStr := pFileReference;
  264.         tFileReferenceNumber := 0;
  265.     end;
  266.     else
  267.         return -50;#gParamError = -50, same as what the tool returns
  268.     
  269.     # Now call the tool with tFilePathStr, tFileReferenceNumber as parameters
  270.     return FileToolHost( "ForgetFile", tFilePathStr, tFileReferenceNumber ); 
  271.     
  272. end;
  273.  
  274. task MoveFileHost( pFileReference, pNewPathName )
  275. begin
  276.     if( typeOf( pFileReference ) = 'integer' )
  277.     begin
  278.         tFilePathStr := '';
  279.         tFileReferenceNumber := pFileReference;
  280.     end;
  281.     else if( typeOf( pFileReference ) = 'string' )
  282.     begin
  283.         tFilePathStr := pFileReference;
  284.         tFileReferenceNumber := 0;
  285.     end;
  286.     else
  287.         return -50;#gParamError = -50, same as what the tool returns
  288.     
  289.     # Now call the tool with tFilePathStr, tFileReferenceNumber and pNewPathName as parameters
  290.     return FileToolHost( "Move", tFilePathStr, tFileReferenceNumber, pNewPathName ); 
  291.     
  292. end;
  293.  
  294. task RenameFileHost( pFileReference, pNewName )
  295. begin
  296.     if( typeOf( pFileReference ) = 'integer' )
  297.     begin
  298.         tFilePathStr := '';
  299.         tFileReferenceNumber := pFileReference;
  300.     end;
  301.     else if( typeOf( pFileReference ) = 'string' )
  302.     begin
  303.         tFilePathStr := pFileReference;
  304.         tFileReferenceNumber := 0;
  305.     end;
  306.     else
  307.         return -50;#gParamError = -50, same as what the tool returns
  308.     
  309.     # Now call the tool with tFilePathStr, tFileReferenceNumber and pNewName as parameters
  310.     return FileToolHost( "Rename", tFilePathStr, tFileReferenceNumber, pNewName ); 
  311.     
  312. end;
  313.  
  314. task VolumeListHost()
  315. begin
  316.     
  317.     # Now call the tool 
  318.     return FileToolHost( "VolumeList" ); 
  319.     
  320. end;
  321.  
  322. # a utility task used by WriteToFile
  323. task ToText( pData )
  324. begin
  325.     if( typeOf( pData ) = 'string' ) return pData;
  326.     if( typeOf( pData ) = 'integer' ) return NumToStr( pData );
  327.     return undefined; # else
  328. end;
  329.  
  330. # This task will append pData to end of the specified file
  331. # pData can a string or a list of strings and numbers
  332. task WriteToFileHost( pFileReference, pData )
  333. begin
  334.     tText := '';
  335.     if( typeOf( pFileReference ) = 'integer' )
  336.     begin
  337.         tFilePathStr := '';
  338.         tFileReferenceNumber := pFileReference;
  339.     end;
  340.     else if( typeOf( pFileReference ) = 'string' )
  341.     begin
  342.         tFilePathStr := pFileReference;
  343.         tFileReferenceNumber := 0;
  344.     end;
  345.     else
  346.         return -50;#gParamError = -50, same as what the tool returns
  347.     
  348.     if( typeOf( pData ) = 'list' )
  349.     begin
  350.         for i := 1 to card pData
  351.         begin
  352.             tNext := ToText( pData[i] );
  353.             if( tNext )
  354.                 tText := tText + tNext;
  355.             else
  356.                 return -50;
  357.         end;
  358.     end;
  359.     else if( typeOf( pData ) = 'string' )
  360.     begin
  361.         tText := pData;
  362.     end;
  363.     else
  364.         return -50;#gParamError = -50, same as what the tool returns
  365.  
  366.     # Now call the tool with tFilePathStr, tFileReferenceNumber and tText as parameters
  367.     return FileToolHost( "Write", tFilePathStr, tFileReferenceNumber, tText ); 
  368.  
  369. end;
  370.  
  371.  
  372. task ReadHost( pFileReference, pNumOfCharacters, pFromPosition := 0 )
  373. begin
  374.     if( typeOf( pFileReference ) = 'integer' )
  375.     begin
  376.         tFilePathStr := '';
  377.         tFileReferenceNumber := pFileReference;
  378.     end;
  379.     else if( typeOf( pFileReference ) = 'string' )
  380.     begin
  381.         tFilePathStr := pFileReference;
  382.         tFileReferenceNumber := 0;
  383.     end;
  384.     else
  385.         return -50;#gParamError = -50, same as what the tool returns
  386.     
  387.     # Now call the tool with tFilePathStr, tFileReferenceNumber and pNumOfCharacters as parameters
  388.     return FileToolHost( "Read", tFilePathStr, tFileReferenceNumber, pNumOfCharacters, pFromPosition ); 
  389.     
  390. end;
  391.  
  392. task ReadUntilHost( pFileReference, pUntilCharacter, pFromPosition := 0 )
  393. begin
  394.     if( typeOf( pFileReference ) = 'integer' )
  395.     begin
  396.         tFilePathStr := '';
  397.         tFileReferenceNumber := pFileReference;
  398.     end;
  399.     else if( typeOf( pFileReference ) = 'string' )
  400.     begin
  401.         tFilePathStr := pFileReference;
  402.         tFileReferenceNumber := 0;
  403.     end;
  404.     else
  405.         return -50;#gParamError = -50, same as what the tool returns
  406.     
  407.     # Now call the tool with tFilePathStr, tFileReferenceNumber and pUntilCharacter as parameters
  408.     return FileToolHost( "ReadUntil", tFilePathStr, tFileReferenceNumber, pUntilCharacter, pFromPosition ); 
  409.     
  410. end;
  411.  
  412. task ReadLineHost( pFileReference, pFromPosition := 0 )
  413. begin
  414.     return ReadUntilHost( pFileReference, "∂n", pFromPosition );
  415. end;
  416.  
  417.  
  418.  
  419.  
  420. task AppendFileHost( pTargetFile, pSourceFile )
  421. begin
  422.     if not ( typeOf( pTargetFile ) = 'string' )
  423.     begin
  424.         return { -50 };#gParamError = -50, same as what the tool returns
  425.     end;
  426.     
  427.     if not ( typeOf( pSourceFile ) = 'string' )
  428.     begin
  429.         return { -50 };#gParamError = -50, same as what the tool returns
  430.     end;
  431.         
  432.     # Now call the tool with tTargetFile, tSourceFile
  433.     x := FileToolHost( "AppendFile", pTargetFile, pSourceFile ); 
  434.     return x;
  435. end;
  436.  
  437. #########################################################################
  438. #    task        InitFindFolderGlobalsHost()
  439. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  440. #    Description:    Initializes global constants for use with FindFolder
  441. #
  442. #    Parameters:        None
  443. #
  444. #    Returns:        Nothing
  445. #
  446. #    Example:        InitFindFolderGlobalsHost()
  447. #
  448. #    Assumptions:    VU 2.1
  449. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  450. #    History:
  451. #        02/04/97    JAS            created 
  452. #########################################################################
  453. task InitFindFolderGlobalsHost()
  454. begin
  455.     # global constants used by FindFolder:
  456.     
  457.     global kSystemFolderType            := "macs";    # the system folder 
  458.     global kDesktopFolderType            := 'desk';    # the desktop folder; objects in this folder show on the desk top. 
  459.     global kTrashFolderType                := 'trsh';    # the trash folder; objects in this folder show up in the trash 
  460.     global kWhereToEmptyTrashFolderType := 'empt';    # the "empty trash" folder; Finder starts empty from here down 
  461.     global kPrintMonitorDocsFolderType    := 'prnt';    # Print Monitor documents 
  462.     global kStartupFolderType            := 'strt';    # Finder objects (applications, documents, DAs, aliases, to...) to open at startup go here 
  463.     global kShutdownFolderType            := 'shdf';    # Finder objects (applications, documents, DAs, aliases, to...) to open at shutdown go here 
  464.     global kAppleMenuFolderType            := 'amnu';    # Finder objects to put into the Apple menu go here 
  465.     global kControlPanelFolderType        := 'ctrl';    # Control Panels go here (may contain INITs) 
  466.     global kExtensionFolderType            := 'extn';    # Finder extensions go here 
  467.     global kFontsFolderType                := 'font';    # Fonts go here 
  468.     global kPreferencesFolderType        := 'pref';    # preferences for applications go here 
  469.     global kTemporaryFolderType            := 'temp';    # the Temporary Folder inside the System folder
  470. end;
  471.  
  472.  
  473. task FindFolderHost( FolderType )
  474. begin
  475.     if not ( typeOf( FolderType ) = 'string' )
  476.     begin
  477.         return { errAEWrongParameters, undef, "Bad FolderType parameter" };
  478.     end;
  479.     
  480.     if ( card( FolderType ) > 4 ) or ( card( FolderType ) <= 0 ) 
  481.     begin
  482.         return { errAEWrongParameters, undef, "Bad FolderType parameter" };
  483.     end;
  484.     
  485.     x := FileToolHost( "FindFolder", FolderType ); 
  486.     return x;
  487. end;
  488.  
  489. task ReadVersionHost( FilePathName, pVersID := 1 )
  490. begin
  491.     x := FileToolHost( "ReadVersion", FilePathName, pVersID ); 
  492.     SErr := ScriptError();
  493.     return { x[1], x[2], x[3], SErr };
  494. end;
  495.  
  496. task ResourceExistsHost( FilePathName, pResType, pResID )
  497. begin
  498.     x := FileToolHost( "ResourceExists", FilePathName, pResType, pResID ); 
  499.     SErr := ScriptError();
  500.     return { x[1], x[2], x[3], SErr };
  501. end;
  502.  
  503. task ReadSizeResourceHost( FilePathName, pResID )
  504. begin
  505.     x := FileToolHost( "ReadSizeResource", FilePathName, pResID ); 
  506.     SErr := ScriptError();
  507.     return { x[1], x[2], x[3], SErr };
  508. end;
  509.  
  510.